// import axios from 'axios'
import $ from 'jquery'
import { Loading } from 'element-ui';
import { Message } from "element-ui";


(function () {
  let t = {}
    // t.baseurl = 'http://192.168.20.122:8080/'
    t.baseurl = 'http://chinacommunity.bilur.io/'
    // t.imgurl = 'http://13.125.227.83:80'
    t.imgurl = 'http://chinacommunity.bilur.io'
    t.jiaoyiUrl = 'http://52.79.213.0/',//交易所
  t.url = {
    login: t.baseurl + 'ChinaCommunity/font/member/login', //登录
    buildWarehouse: t.baseurl + 'ChinaCommunity/font/building/getPersonBuildingList', //建仓列表
    goWarehouse: t.baseurl + 'ChinaCommunity/font/building/addFontBuilding', //建仓申请
    checkerdu: t.baseurl + 'ChinaCommunity/font/building/gotoFontAddBuilding', // 建仓额度
    announcementList: t.baseurl + 'ChinaCommunity/font/notice/getFontNoticeList', //公告列表接口
    getPickup: t.baseurl + 'ChinaCommunity/font/pickup/savePickup', //提货管理
    getWithDraw: t.baseurl + 'ChinaCommunity/font/withdraw/gotoFontAddWithDraw', //提现申请余额
    goWithDraw: t.baseurl + 'ChinaCommunity/font/withdraw/addWithDraw', //提现申请
    pickupList: t.baseurl + 'ChinaCommunity/font/pickup', //提货列表
    withdrawList: t.baseurl + 'ChinaCommunity/font/withdraw', //提现列表
    futou: t.baseurl + 'ChinaCommunity/font/recast/getAllRecastList', //复投管理的展示
    futouStyle: t.baseurl + 'ChinaCommunity/font/recast/getFontRecastListByCondition', //根据时间范围、复投类型、选择类型查询
    shengqingfutou: t.baseurl + 'ChinaCommunity/font/recast/addRecast', //申请复投
    announcementDetails: t.baseurl + 'ChinaCommunity/font/notice/findNoticeInfoById', //公告详情的接口
    newList: t.baseurl + 'ChinaCommunity/font/consult/getConsultList', //资讯列表接口
    newsDetails: t.baseurl + 'ChinaCommunity/font/consult/getConsultListInfo', //资讯详情接口
    getPersonLetter: t.baseurl + 'ChinaCommunity/font/letter/getPersonLetter', //发件箱展示接口
    findLetterDetail: t.baseurl + 'ChinaCommunity/font/letter/findLetterDetail', //发件箱详示接口
    userTree: t.baseurl + 'ChinaCommunity/font/member/userTree', // 推广列表
    tixian: t.baseurl + 'ChinaCommunity/font/withdraw', // 前端提现列表
    writeLetters: t.baseurl + 'ChinaCommunity/font/letter/addPersonLetter', //写信接口
    addressee: t.baseurl + 'ChinaCommunity/font/letter/getPersonLetter', //收件箱展示接口
    receiptDetail: t.baseurl + 'ChinaCommunity/font/letter/findLetterDetail',//收件箱详情接口
    receiptDelete: t.baseurl + 'ChinaCommunity/font/letter/deleteLetter',//收件箱删除接口
    receiptQuery: t.baseurl + 'ChinaCommunity/font/letter/getPersonLetter',//收件箱根据时间和状态查询接口
    deleteSendLetter: t.baseurl + 'ChinaCommunity/font/letter/deleteLetter',//发件箱删除接口
    register: t.baseurl + '/ChinaCommunity/font/member/register',//注册
    sendTime: t.baseurl + 'ChinaCommunity/font/letter/getPersonLetter',//根据发件时间查询接口
    jiaoyiAccount: t.jiaoyiUrl + 'appUser/appuser/getUserInfo',//交易所账号验证接口
    jiaoyiBand: t.baseurl + 'ChinaCommunity/font/member/updateMember',//交易所账号绑定接口
    BWmail: t.baseurl + 'ChinaCommunity/font/member/getBwCode',//币旺邮件接口
    BWbind: t.baseurl + 'ChinaCommunity/font/member/updateBwAccount',//币旺绑定接口
    RWmail: t.baseurl + 'ChinaCommunity/font/member/getRwCode',//R网邮件接口
    RWbind: t.baseurl + 'ChinaCommunity/font/member/updateRwAccount',//币旺绑定接口
    getuserInfo: t.baseurl + 'ChinaCommunity/font/member/userInfo',//获取个人信息
    getLink: t.baseurl + 'ChinaCommunity/font/member/getSpreadLink', // 推广链接
    getPickups: t.baseurl + 'ChinaCommunity/font/pickup/getPickup',//提货支付回写
    payPickup: t.baseurl + 'ChinaCommunity/font/pickup/payPickup',//提货支付提交
    yzm: t.baseurl + "ChinaCommunity/font/member/sendMessage",//短信验证码
    yzmlogin: t.baseurl + "ChinaCommunity/font/member/messageLogin",//验证码登录
    jcmoney: t.baseurl + 'ChinaCommunity/font/building/gotoPayBuilding',//建仓支付查询
    payjcmoney: t.baseurl + 'ChinaCommunity/font/building/payBuilding',//建仓支付
    zjdetails: t.baseurl + 'ChinaCommunity/font/financing/getFinanceList',//资金明细
    wjpassword: t.baseurl + "ChinaCommunity/font/member/forgetPassword",//忘记密码
    wjpasswordyz: t.baseurl + 'ChinaCommunity/font/member/codeValidate',//忘记密码验证
    unreadNum: t.baseurl + 'ChinaCommunity/font/letter/findPersonLetterIsRead',//查询收件箱未读数量的接口
    userInfo: t.baseurl + 'ChinaCommunity/font/member/userNowInfo',// 个人信息
    getbankinfo: t.baseurl + 'ChinaCommunity/font/financing/getYeasFinanceInfo',//查询以启用收款卡号信息
    modifyPassword: t.baseurl + 'ChinaCommunity/font/member/modifyPassword',//修改密码
    updateMember: t.baseurl + 'ChinaCommunity/font/member/updateNewMember',//更改人员信息
    logout: t.baseurl + 'ChinaCommunity/font/member/logout',//登出
    financialsummary: t.baseurl + 'ChinaCommunity/font/member/finaceCenter',//财务汇总
    indexTable: t.baseurl + 'ChinaCommunity/font/member/homeList',//首页直推
    summary: t.baseurl + 'ChinaCommunity/font/member/finaceCenter',//财务汇总
    yonJin: t.baseurl + 'ChinaCommunity/font/member/weekGoal',//获取每周目标和当前人本周的佣金
    financialsummary: t.baseurl + 'ChinaCommunity/font/member/finaceCenter',//财务汇总
    checkedjcmoney: t.baseurl + 'ChinaCommunity/admin/chainSetting/queryByName',//查询建仓价格
    getBpxGinsengRate:t.baseurl + 'ChinaCommunity/font/pickup/getBpxGinsengRate',//bpx汇率
    updateIntroduceStatus:t.baseurl + 'ChinaCommunity/font/member/updateIntroduceStatus',//更新第一次登录的指引
  }
  t.loginflag = true;
  t.ajax = (obj, callback, fail) => {
    if (callback && typeof callback == 'function') {
      let loadingInstance = Loading.service({
        lock: true,
        text: 'Loading',
        background: 'rgba(0, 0, 0, 0.7)'
      });
      let data;
      if (obj.dataJsonp) {
        data = JSON.stringify(obj.dataJsonp)
        data.lastIndexOf(',') == data.length - 2
        data = data.substring(data.lastIndexOf(','), 1)
        data = JSON.parse(data)
      } else if (obj.data) {
        data = JSON.stringify(obj.data)
        data.lastIndexOf(',') == data.length - 2 ?
          data = data.substring(data.lastIndexOf(','), 1) : ''
      }
      $.ajax({
        url: obj.url, //可以不是本地域名
        type: obj.type,
        dataType: obj.json || 'json', //jsonp格式访问
        contentType: obj.contentType || 'application/json;charset=utf-8',
        data: obj.dataJsonp || JSON.stringify(obj.data),
        success: function (data) {
          if (data.code == '2011' && t.loginflag) {
            t.loginflag = false;
            setTimeout(() => {
              loadingInstance.close()
              t.loginflag = true
              window.location.hash = '#/login'
            }, 1000)
            return Message({
              message: "登录失效请重新登录",
              type: "error",
              duration: 1000
            });
          }

          callback(data)
          setTimeout(() => {
            loadingInstance.close()
          }, 1000)

        },
        error: function (xml, parsererror) {
          setTimeout(() => {
            loadingInstance.close()
          }, 1000)
          fail && typeof fail == 'function' ? fail() : ''
          console.log('失败')
        }
      })
    } else {
      console.log('请输入正确的回调类型')
    }

  }
  // t.axios = (obj, callback, fail) => {
  //     if (obj && typeof callback == 'function') {
  //         !fail || typeof fail == 'function' ? axios({
  //             methods: obj.type,
  //             data: obj.data || {},
  //             url: obj.url,
  //             headers: {
  //                 'Content-Type': obj.contentType || 'application/json;charset=utf-8',
  //             }
  //         }).then(callback).catch(fail) : console.log('请输入正确的错误回调类型')
  //     } else {
  //         console.log('请输入正确的回调类型')
  //     }

  // }
  t.getBpxGinsengRate = (callback)=>{
    t.ajax({
      url: t.url.getBpxGinsengRate,
      type: 'get',
    }, callback)
  }
  t.checkedjcmoney = (data, callback) => {
    t.ajax({
      url: t.url.checkedjcmoney,
      type: 'post',
      data: data
    }, callback)
  }
  t.indexTable = (callback) => {
    t.ajax({
      url: t.url.indexTable,
      type: 'get',
    }, callback)
  }
  t.financialsummary = (callback) => {
    t.ajax({
      url: t.url.financialsummary,
      type: 'get',
    }, callback)
  }
  t.getbankinfo = (callback) => {
    t.ajax({
      url: t.url.getbankinfo,
      type: 'post',
      data: {}
    }, callback)
  }
  t.userInfo = (data, callback) => {
    t.ajax({
      url: t.url.userInfo,
      data: data,
      type: 'post'
    }, callback)
  }
  t.updateIntroduceStatus = (data, callback) => {
    t.ajax({
      url: t.url.updateIntroduceStatus,
      data: data,
      type: 'post'
    }, callback)
  }
  t.login = (data, callback) => {
    t.ajax({
      url: t.url.login,
      data: data,
      type: 'post'
    }, callback)
  }
  t.logout = (callback) => {
    t.ajax({
      url: t.url.logout,
      type: 'get'
    }, callback)
  }

  t.buildWarehouse = (data, callback) => {
    t.ajax({
      url: t.url.buildWarehouse,
      data: data,
      type: 'post'
    }, callback)
  }
  t.goWarehouse = (data, callback) => {
    t.ajax({
      url: t.url.goWarehouse,
      data: data,
      type: 'post'
    }, callback)
  }
  t.checkerdu = (data,callback) => {
    t.ajax({
      url: t.url.checkerdu,
      type: 'post',
      data:data
    }, callback)
  }
  //公告列表
  t.announcementList = (data, callback) => {
    t.ajax({
      url: t.url.announcementList,
      type: 'post',
      data: data
    }, callback)
  }
  t.getPickup = (data, callback) => {
    t.ajax({
      url: t.url.getPickup,
      data: data,
      type: 'post'
    }, callback)
  }
  t.getWithDraw = (callback) => {
    t.ajax({
      url: t.url.getWithDraw,
      type: 'get'
    }, callback)
  }
  t.goWithDraw = (data, callback) => {
    t.ajax({
      url: t.url.goWithDraw,
      data: data,
      type: 'post'
    }, callback)
  }
  t.pickupList = (data, callback) => {
    t.ajax({
      url: t.url.pickupList,
      data: data,
      type: 'post'
    }, callback)
  }
  t.payPickup = (data, callback) => {
    t.ajax({
      url: t.url.payPickup,
      data: data,
      type: 'post'
    }, callback)
  }
  t.getPickups = (data, callback) => {
    t.ajax({
      url: t.url.getPickups,
      data: data,
      type: 'post'
    }, callback)
  }
  t.withdrawList = (data, callback) => {
    t.ajax({
      url: t.url.withdrawList,
      data: data,
      type: 'post'
    }, callback)
  }
  t.futou = (data, callback) => {
    t.ajax({
      url: t.url.futou,
      data: data,
      type: 'post'
    }, callback)
  }

  t.futouStyle = (data, callback) => {
    t.ajax({
      url: t.url.futouStyle,
      data: data,
      type: 'post'
    }, callback)
  }
  t.shengqingfutou = (data, callback) => {
    data.name = 'rst'
    t.ajax({
      url: t.url.shengqingfutou,
      data: data,
      type: 'post'
    }, callback)
  }
  //公告详情
  t.announcementDetails = (data, callback) => {
    t.ajax({
      url: t.url.announcementDetails,
      data: data,
      type: 'post'
    }, callback)
  }
  //资讯
  t.newList = (data, callback) => {
    t.ajax({
      url: t.url.newList,
      data: data,
      type: 'post'
    }, callback)
  }
  t.newsDetails = (data, callback) => {
    t.ajax({
      url: t.url.newsDetails,
      data: data,
      type: 'post'
    }, callback)
  }
  //发件箱展示
  t.getPersonLetter = (data, callback) => {
    t.ajax({
      url: t.url.getPersonLetter,
      data: data,
      type: 'post'
    }, callback)
  }
  //发件箱详情展示
  t.findLetterDetail = (data, callback) => {
    t.ajax({
      url: t.url.findLetterDetail,
      data: data,
      type: 'post'
    }, callback)
  }
  //写信接口
  t.writeLetters = (data, callback) => {
    t.ajax({
      url: t.url.writeLetters,
      data: data,
      type: 'post'
    }, callback)
  }
  //收件箱展示
  t.addressee = (data, callback) => {
    t.ajax({
      url: t.url.addressee,
      data: data,
      type: 'post'
    }, callback)
  }
  //收件箱详情
  t.receiptDetail = (data, callback) => {
    t.ajax({
      url: t.url.receiptDetail,
      data: data,
      type: 'post'
    }, callback)
  }
  //收件箱删除
  t.receiptDelete = (data, callback) => {
    t.ajax({
      url: t.url.receiptDelete,
      data: data,
      type: 'post'
    }, callback)
  }
  //发件箱删除
  t.deleteSendLetter = (data, callback) => {
    t.ajax({
      url: t.url.deleteSendLetter,
      data: data,
      type: 'post'
    }, callback)
  }
  //收件箱根据时间和状态查询接口
  t.receiptQuery = (data, callback) => {
    t.ajax({
      url: t.url.receiptQuery,
      data: data,
      type: 'post'
    }, callback)
  }
  t.register = (data, callback) => {
    t.ajax({
      url: t.url.register,
      data: data,
      type: 'post'
    }, callback)
  }

  //根据发件时间查询
  t.sendTime = (data, callback) => {
    t.ajax({
      url: t.url.sendTime,
      data: data,
      type: 'post'
    }, callback)
  }
  //验证交易所账号
  t.jiaoyiAccount = (data, callback) => {
    t.ajax({
      url: t.url.jiaoyiAccount,
      data: data,
      type: 'post'
    }, callback)
  }
  //绑定交易所账号
  t.jiaoyiBand = (data, callback) => {
    t.ajax({
      url: t.url.jiaoyiBand,
      data: data,
      type: 'post'
    }, callback)
  }
  //BW发送邮件
  t.BWmail = (data, callback) => {
    t.ajax({
      url: t.url.BWmail,
      data: data,
      type: 'post'
    }, callback)
  }
  t.userTree = (data, callback) => {
    t.ajax({
      url: t.url.userTree,
      data: data,
      type: 'post'
    }, callback)
  }
  //BW绑定
  t.BWbind = (data, callback) => {
    t.ajax({
      url: t.url.BWbind,
      data: data,
      type: 'post'
    }, callback)
  }
  //RW发送邮件
  t.RWmail = (data, callback) => {
    t.ajax({
      url: t.url.RWmail,
      data: data,
      type: 'post'
    }, callback)
  }
  //RW绑定
  t.RWbind = (data, callback) => {
    t.ajax({
      url: t.url.RWbind,
      data: data,
      type: 'post'
    }, callback)
  }
  //获取个人信息
  t.getuserInfo = (callback) => {
    t.ajax({
      url: t.url.getuserInfo,
      // data: data,
      type: 'get'
    }, callback)
  }
  t.getLink = (callback) => {
    t.ajax({
      url: t.url.getLink,
      type: 'get'
    }, callback)
  }
  t.yzm = (data, callback) => {
    t.ajax({
      url: t.url.yzm,
      data: data,
      type: 'post'
    }, callback)
  }
  t.yzmlogin = (data, callback) => {
    t.ajax({
      url: t.url.yzmlogin,
      data: data,
      type: 'post'
    }, callback)
  }
  t.jcmoney = (data, callback) => {
    t.ajax({
      url: t.url.jcmoney,
      data: data,
      type: "post"
    }, callback)
  }
  t.payjcmoney = (data, callback) => {
    t.ajax({
      url: t.url.payjcmoney,
      data: data,
      type: "post"
    }, callback)
  }
  t.zjdetails = (data, callback) => {
    t.ajax({
      url: t.url.zjdetails,
      data: data,
      type: "post"
    }, callback)
  }
  t.wjpassword = (data, callback) => {
    t.ajax({
      url: t.url.wjpassword,
      data: data,
      type: "post"
    }, callback)
  }
  t.wjpasswordyz = (data, callback) => {
    t.ajax({
      url: t.url.wjpasswordyz,
      data: data,
      type: "post"
    }, callback)
  }
  //查询收件箱未读数量的接口
  t.unreadNum = (data, callback) => {
    t.ajax({
      url: t.url.unreadNum,
      data: data,
      type: "post"
    }, callback)
  }
  t.setUser = (callback) => {

    t.userInfo({ id: localStorage.getItem("userID") }, data => {
      if (data && data.code == "200") {
        localStorage.setItem("userData", JSON.stringify(data.data));
        typeof callback == 'function' ? callback() : ''
        // if (data.data.exchangeBind == "1" && data.data.bwBind == "1") {
        //   localStorage.setItem("sfyz", "1");
        // } else {
        //   localStorage.setItem("sfyz", "2");
        // }
        localStorage.setItem('jcflag',data.data.bwBind)
      }
    });
  }
  //忘记密码
  t.modifyPassword = (data, callback) => {
    t.ajax({
      url: t.url.modifyPassword,
      data: data,
      type: "post"
    }, callback)
  }
  //更改人员信息
  t.updateMember = (data, callback) => {
    t.ajax({
      url: t.url.updateMember,
      data: data,
      type: "post"
    }, callback)
  }
  //财务汇总
  t.summary = (callback) => {
    t.ajax({
      url: t.url.summary,
      // data: data,
      type: "get"
    }, callback)
  }
  //本周佣金
  t.yonJin = (callback) => {
    t.ajax({
      url: t.url.yonJin,
      // data: data,
      type: "get"
    }, callback)
  }
  window.u = t;
})()

export default u
